//
//  OrderStatusView.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/26.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "OrderStatusView.h"
#define ORDER_STATUS_TEXT1_SIZE  [DimensUtils getScaleX:14]
#define ORDER_STATUS_TEXT2_SIZE  [DimensUtils getScaleX:10]
@interface OrderStatusView()
{
    UIImageView *_cartIconImageView;
    UILabel *_cartLabel;
    UILabel *_cartLabel2;
    UIButton *_scrollButton;
}
@end

@implementation OrderStatusView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //状态图片
        UIImage *img = [UIImage imageNamed:@"order_status_success"];
        _cartIconImageView = [[UIImageView alloc ]initWithImage:img];
        [_cartIconImageView setFrame:CGRectMake(JXPublicInset, 0, img.size.width, img.size.height)];
        [self addSubview:_cartIconImageView];
       
        //文字1
        NSString *nullStr = @"订单提交成功";
        _cartLabel = [[UILabel alloc]init];
        [_cartLabel setText:nullStr];
        [_cartLabel setFont:[UIFont systemFontOfSize:ORDER_STATUS_TEXT1_SIZE]];
        [_cartLabel setTextColor:JXColor(77, 77, 77)];
        CGSize nullStrSize = [nullStr sizeWithFont:[UIFont systemFontOfSize:ORDER_STATUS_TEXT1_SIZE]];
        [_cartLabel setFrame:CGRectMake((135-nullStrSize.width)/2, CGRectGetMaxY(_cartIconImageView.frame)+JXPublicInset, nullStrSize.width, nullStrSize.height)];
        [self addSubview:_cartLabel];
        //文字2
        NSString *selectStr = @"我们的快递员正在拼命的配送";
        _cartLabel2 = [[UILabel alloc]init];
        [_cartLabel2 setText:selectStr];
        [_cartLabel2 setFont:[UIFont systemFontOfSize:ORDER_STATUS_TEXT2_SIZE]];
        [_cartLabel2 setTextColor:JXColor(77, 77, 77)];
        CGSize selectStrSize = [selectStr sizeWithFont:[UIFont systemFontOfSize:ORDER_STATUS_TEXT2_SIZE]];
        [_cartLabel2 setFrame:CGRectMake((135-selectStrSize.width)/2, CGRectGetMaxY(_cartLabel.frame)+5, selectStrSize.width, selectStrSize.height)];
        [self addSubview:_cartLabel2];
        //查看订单按钮
        _scrollButton =[[UIButton alloc]init];
        [_scrollButton setTitle:@"查看订单" forState:UIControlStateNormal];
        [_scrollButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_scrollButton setContentMode:UIViewContentModeCenter];
        [_scrollButton setBackgroundImage:[UIImage resizedImage:@"btn_login_bg"] forState:UIControlStateNormal];
        [_scrollButton addTarget:self action:@selector(didNext) forControlEvents:UIControlEventTouchUpInside];
        [_scrollButton setFrame:CGRectMake(0, CGRectGetMaxY(_cartLabel2.frame)+JXPublicInset*2, 135, 37.5)];
        [self addSubview:_scrollButton];
        
        [self setSize:CGSizeMake(135, CGRectGetMaxY(_scrollButton.frame))];
    }
    return self;
}

/**
 *  点击按钮
 */
-(void)didNext{
    if ([self.delegate respondsToSelector:@selector(didNext)]) {
        [_delegate didNext];
    }
}

/**
 *  设置状态图片
 *
 *  @param img
 */
-(void)setStatusImg:(NSString *)img{
    UIImage *statusImg = [UIImage imageNamed:img];
    [_cartIconImageView setSize:CGSizeMake(statusImg.size.width, statusImg.size.height)];
    [_cartIconImageView setImage:statusImg];
}

/**
 *  设置按钮的文字
 *
 *  @param text
 */
-(void)setBtnText:(NSString *)text{
    [_scrollButton setTitle:text forState:UIControlStateNormal];
}

/**
 *  设置第一行文字
 *
 *  @param text 文字
 */
-(void)setOneText:(NSString *)text{
    
    [_cartLabel setText:text];
}

/**
 *  设置第二行文字
 *
 *  @param text 文字
 */
-(void)setTwoText:(NSString *)text{
    CGSize selectStrSize = [text sizeWithFont:[UIFont systemFontOfSize:ORDER_STATUS_TEXT2_SIZE]];
    [_cartLabel2 setFrame:CGRectMake((135-selectStrSize.width)/2, CGRectGetMaxY(_cartLabel.frame)+5, selectStrSize.width, selectStrSize.height)];
    [_cartLabel2 setText:text];
}

@end
